//
//  HomePageViewController.m
//  TheEer
//
//  Created by Qianfeng on 15/10/20.
//  Copyright (c) 2015年 小R. All rights reserved.
//

#import "HomePageViewController.h"

static HomePageViewController * home = nil;
@interface HomePageViewController (){
    //创建一个View用来装midView
    UIView * _midMask;
}

@end

@implementation HomePageViewController

+ (HomePageViewController *)shareSingleton{
    @synchronized(self){
        if (!home) {
            home = [self new];
        }
    }
    return home;
}

- (void)setMidView:(UIViewController *)midView{
    if (_midView != midView) {
        _midView = midView;
    }
    [self.view addSubview:_midView.view];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //初始化点击恢复状态
    _midMask = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    UITapGestureRecognizer * gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resetViewFrame)];
    [_midMask addGestureRecognizer:gesture];
}

+ (void)resetViewFrame{
    [home resetViewFrame];
}

- (void)resetViewFrame{
    [UIView animateWithDuration:.3 animations:^{
        _midView.view.transform = CGAffineTransformMakeScale(1, 1);
        [_midView.view setXOffset:0];
        [RightPageViewController viewDismiss];
    } completion:^(BOOL finished) {
        [_midMask removeFromSuperview];
    }];
}

+ (void)showRightViewController{
    [home showRightView];
}

- (void)showRightView{
    [_midView.view addSubview:_midMask];
    [self.view insertSubview:self.rightView.view belowSubview:self.midView.view];
    if (self.rightView != nil) {
        [UIView animateWithDuration:.3 animations:^{
            [_midView.view setXOffset:-ScreenWidth*4 / 7];
            _midView.view.transform = CGAffineTransformMakeScale(.8, .8);

            [RightPageViewController viewAppear];
        } completion:^(BOOL finished) {
            
        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
